package com.aat.func;

import java.io.File;
import java.io.IOException;

import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.FileEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;

public class BaiduAudioKnowTest {

	public static void main(String[] args) throws IOException {
		// 10305723，GB7ogAMH5vbzxH0HfDusGsDQ，zEo5KXQZMNAXADvDdVXYrQXBpU6vgHnF
		// 24.bb06aa7d3b8c90a5825ad6a47dab378e.2592000.1512022129.282335-10305723

		// String url =
		// "https://openapi.baidu.com/oauth/2.0/token?grant_type=client_credentials&client_id=GB7ogAMH5vbzxH0HfDusGsDQ&client_secret=zEo5KXQZMNAXADvDdVXYrQXBpU6vgHnF&";

		String url = "http://vop.baidu.com/server_api?lan=zh&cuid=AS-WX-3E-D3-3D-SS&token=24.bb06aa7d3b8c90a5825ad6a47dab378e.2592000.1512022129.282335-10305723";
		CloseableHttpClient client = HttpClients.createDefault();

		HttpPost post = new HttpPost(url);
		post.setHeader("Content-Type", "audio/pcm;rate=16000");

		File file = new File("");
		FileEntity entity = new FileEntity(file);
		post.setEntity(entity);

		org.apache.http.client.methods.CloseableHttpResponse resp = client.execute(post);
		org.apache.http.HttpEntity re = resp.getEntity();
		String res = EntityUtils.toString(re);
		System.out.println(res);
		EntityUtils.consume(re);
		if (post != null) {
			post.releaseConnection();
		}
		if (resp != null) {
			resp.close();
		}
		client.close();

	}

}
